﻿using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Documents;
using System.Data.OleDb;
using System.Data;
using System.Collections;

using DopWebService.intelray.webservice;
using DopWebService;
using System.Web.Services;


namespace DataMining.Control.Transport
{
    class GetMDT
    {

        #region 将Excel中的MDT的属性名存成字符型数组,输入：工作表名，输出：属性数组
        public string[] ReadFromExcel(string excel_sheetname)
        {
            DataTable dta = new DataTable();
            string ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:/aa.xls;Extended Properties='Excel 8.0;HDR=Yes;IMEX=0';";
            OleDbConnection cnnxls = new OleDbConnection(ConnStr);
            //读取Excel里面有 表Sheet1
            OleDbDataAdapter oda = new OleDbDataAdapter("select * from [" + excel_sheetname + "$]", cnnxls);
            //将Excel里面有表内容装载到内存表中！
            oda.Fill(dta);

            //将MDT属性转化为string数组
            string[] attribute = new String[dta.Rows.Count];
            for (int i = 0; i <= dta.Rows.Count-1; i++)
            {
                attribute[i] = dta.Rows[i][3].ToString();
            }
            return attribute;
        }
        #endregion


        //取到相应MDT里的相应属性放入datatable，考虑一下？？？？datatable的列名（MDT名）???
        public DataTable GetdataWS(String mdtname, String[] attrnames)
        {

            DopService s = new DopService();
            s.Url = "http://192.168.10.228:8080/DopWebService/services/DopService?wsdl";

            DopServiceHelp help = new DopServiceHelp(s);

            String expression = " <%creat_time%> >" + DateTime.Now.AddDays(-7).ToString();
            String orderByAttr = "creat_time";
            DataTable[] tables = help.GetDataByExpression(mdtname, expression, attrnames, null, null, false, null, orderByAttr);

            DataTable table = null;
            if (tables != null)
                table = tables[0];
            return table;


        }

        public void getDataByExpressionWithCriteria(DopServiceHelp help)
        {

            //DataTable dt = null;
            //dt = getPatientInformationRecordWard(null, help,);
            //dt = getPatient_information_DataTable(help);
            //dt = getMedicalRecordRecordWard(null, help);
            //dt = getOutpatient_registration_DataTable(help);
            //dt = getInpatient_record_DataTable(help);
            //dt = getOutpatient_physician_order_DataTable(help);
            //dt = getDrAdviceDetailRecordWard(null,help);
            //dt = getInpatient_patient_settle_DataTable(help);
            //dt = getPatient_settle_DataTable(help);
            //dt = getFeeRecordRecordWard(null, help);
            //dt = getPatient_fee_record_DataTable(help);
            //dt = getFeeDetailRecordWard(null, help);
            //dt = getLab_Report_DataTable(help);
            //dt = getLISReportRecordWard(null, help);
            //dt = getLab_Result_DataTable(help);
            //dt = getLISIndicatorsRecordWard(null, help);
            //dt = getBacteria_test_result_DataTable(help);
            //dt = getDrug_susceptibility_test_result_DataTable(help);
            //dt = getLISALLergyResultRecordWard(null, help);
            //if (dt != null)
            //dataGridView1.DataSource = dt;

        }

        #region 查询patient_information_MDT全部信息
        public System.Data.DataTable getPatient_information_DataTable(DopServiceHelp help)
        {
            //mdtname要查询的数据所属的MDT的名称。
            String mdtname = "patient_information_MDT";

            //expression: 类似于SQL表达式，但属性名称要用<%%>封装。
            //String expression = "<%name%> like '王新%'";
            //String expression = "<%name%> = '" + patientName + "'";
            DataTable table = help.GetDataByExpression(mdtname, "");
            return table;
        }
        #endregion

        #region 查询outpatient_registration_MDT全部信息
        public System.Data.DataTable getOutpatient_registration_DataTable(DopServiceHelp help)
        {
            //mdtname要查询的数据所属的MDT的名称。
            String mdtname = "outpatient_registration_MDT";

            //expression: 类似于SQL表达式，但属性名称要用<%%>封装。
            //String expression = "<%name%> like '王新%'";
            //String expression = "<%name%> = '" + patientName + "'";
            DataTable table = help.GetDataByExpression(mdtname, "");
            return table;
        }
        #endregion

        #region 查询inpatient_record_MDT全部信息
        //public System.Data.DataTable getInpatient_record_DataTable(DopServiceHelp help)
        //{
        //    //mdtname要查询的数据所属的MDT的名称。
        //    String mdtname = "inpatient_record_MDT";

        //    //expression: 类似于SQL表达式，但属性名称要用<%%>封装。
        //    //String expression = "<%name%> like '王新%'";
        //    //String expression = "<%name%> = '" + patientName + "'";
        //    DataTable table = help.GetDataByExpression(mdtname, "");
        //    return table;
        //}
        #endregion

        #region 查询outpatient_physician_order_MDT全部信息
        public System.Data.DataTable getOutpatient_physician_order_DataTable(DopServiceHelp help)
        {
            //mdtname要查询的数据所属的MDT的名称。
            String mdtname = "outpatient_physician_order_MDT";

            //expression: 类似于SQL表达式，但属性名称要用<%%>封装。
            //String expression = "<%name%> like '王新%'";
            //String expression = "<%name%> = '" + patientName + "'";
            DataTable table = help.GetDataByExpression(mdtname, "");
            return table;
        }
        #endregion

        #region 查询inpatient_patient_settle_MDT全部信息
        public System.Data.DataTable getInpatient_patient_settle_DataTable(DopServiceHelp help)
        {
            //mdtname要查询的数据所属的MDT的名称。
            String mdtname = "inpatient_patient_settle_MDT";

            //expression: 类似于SQL表达式，但属性名称要用<%%>封装。
            //String expression = "<%name%> like '王新%'";
            //String expression = "<%name%> = '" + patientName + "'";
            DataTable table = help.GetDataByExpression(mdtname, "");
            return table;
        }
        #endregion

        #region 查询patient_settle_MDT全部信息
        //public System.Data.DataTable getPatient_settle_DataTable(DopServiceHelp help)
        //{
        //    //mdtname要查询的数据所属的MDT的名称。
        //    String mdtname = "patient_settle_MDT";

        //    //expression: 类似于SQL表达式，但属性名称要用<%%>封装。
        //    //String expression = "<%name%> like '王新%'";
        //    //String expression = "<%name%> = '" + patientName + "'";
        //    DataTable table = help.GetDataByExpression(mdtname, "");
        //    return table;
        //}
        #endregion

        #region 查询patient_fee_record_MDT全部信息
        public System.Data.DataTable getPatient_fee_record_DataTable(DopServiceHelp help)
        {
            //mdtname要查询的数据所属的MDT的名称。
            String mdtname = "patient_fee_record_MDT";

            //expression: 类似于SQL表达式，但属性名称要用<%%>封装。
            //String expression = "<%name%> like '王新%'";
            //String expression = "<%name%> = '" + patientName + "'";
            DataTable table = help.GetDataByExpression(mdtname, "");
            return table;
        }
        #endregion

        #region 查询lab_report_MDT全部信息
        public System.Data.DataTable getLab_Report_DataTable(DopServiceHelp help)
        {
            //mdtname要查询的数据所属的MDT的名称。
            String mdtname = "lab_report_MDT";

            //expression: 类似于SQL表达式，但属性名称要用<%%>封装。
            //String expression = "<%name%> like '王新%'";
            //String expression = "<%name%> = '" + patientName + "'";
            DataTable table = help.GetDataByExpression(mdtname, "");
            return table;
        }

        #endregion

        #region 查询lab_result_MDT全部信息
        public System.Data.DataTable getLab_Result_DataTable(DopServiceHelp help)
        {
            //mdtname要查询的数据所属的MDT的名称。
            String mdtname = "lab_result_MDT";

            //expression: 类似于SQL表达式，但属性名称要用<%%>封装。
            //String expression = "<%name%> like '王新%'";
            //String expression = "<%name%> = '" + patientName + "'";
            DataTable table = help.GetDataByExpression(mdtname, "");
            return table;
        }
        #endregion

        #region 查询bacteria_test_result_MDT全部信息
        public System.Data.DataTable getBacteria_test_result_DataTable(DopServiceHelp help)
        {
            //mdtname要查询的数据所属的MDT的名称。
            String mdtname = "bacteria_test_result_MDT";

            //expression: 类似于SQL表达式，但属性名称要用<%%>封装。
            //String expression = "<%name%> like '王新%'";
            //String expression = "<%name%> = '" + patientName + "'";
            DataTable table = help.GetDataByExpression(mdtname, "");
            return table;
        }
        #endregion

        #region 查询drug_susceptibility_test_result_MDT全部信息
        public System.Data.DataTable getDrug_susceptibility_test_result_DataTable(DopServiceHelp help)
        {
            //mdtname要查询的数据所属的MDT的名称。
            String mdtname = "drug_susceptibility_test_result_MDT";

            //expression: 类似于SQL表达式，但属性名称要用<%%>封装。
            //String expression = "<%name%> like '王新%'";
            //String expression = "<%name%> = '" + patientName + "'";
            DataTable table = help.GetDataByExpression(mdtname, "");
            return table;
        }
        #endregion

        #region 获取患者信息表Patient_Information对应的patient_information_MDT
        public DataTable getPatientInformationRecordWard(int seqid, DopServiceHelp help, string[] attr)
        {
            DateTime dt1 = DateTime.Now;
            double t1 = dt1.ToOADate();

            String mdtname = "patient_information_MDT";
            String expression = " <%patient_id_seq%> > " + seqid;
            String orderByAttr = "patient_id_seq";
            DataTable[] tables = help.GetDataByExpression(mdtname, expression, attr, null, null, false, null, orderByAttr);

            DataTable table = null;
            if (tables != null)
                table = tables[0];
            return table;
        }
        #endregion

        #region 获取就诊记录表Medical_Record对应的outpatient_registration_MDT
        public DataTable getMedicalRecordRecordWard(int seqid, DopServiceHelp help,string[] attr)
        {
            DateTime dt1 = DateTime.Now;
            double t1 = dt1.ToOADate();

            String expression = " <%encounter_serial_number%> > " + seqid;
            String mdtname = "outpatient_registration_MDT";
            String orderByAttr = "encounter_serial_number";
            DataTable[] tables = help.GetDataByExpression(mdtname, expression, attr, null, null, false, null, orderByAttr);

            DataTable table = null;
            if (tables != null)
                table = tables[0];
            return table;
        }

        #endregion

        #region 获取检验报告单（LIS_Report）对应lab_report_MDT
        public DataTable getLISReportRecordWard(int seqid, DopServiceHelp help, string[] attr)
        {
            DateTime dt1 = DateTime.Now;
            double t1 = dt1.ToOADate();

            String expression = " <%lab_report_id%> > " + seqid;
            String mdtname = "lab_report_MDT";
            String orderByAttr = "lab_report_id";
            DataTable[] tables = help.GetDataByExpression(mdtname, expression, attr, null, null, false, null, orderByAttr);

            DataTable table = null;
            if (tables != null)
                table = tables[0];
            return table;
        }
        #endregion 
        //有问题主键是字符型，不能使用seq自增方法取到

        #region 获取门诊医嘱明细表（Outpatient_DrAdvice_Detail）对应outpatient_physician_order_MDT
        public DataTable getOutpatientDrAdviceDetailRecordWard(int seqid, DopServiceHelp help, string[] attr)
        {

            DateTime dt1 = DateTime.Now;
            double t1 = dt1.ToOADate();

            String expression = " <%physician_order_serial_number_seq%> > " + seqid;
            String mdtname = "outpatient_physician_order_MDT";
            String orderByAttr = "physician_order_serial_number_seq";
            Console.WriteLine(expression);
            DataTable[] tables = help.GetDataByExpression(mdtname, expression, attr, null, null, false, null, orderByAttr);

            DataTable table = null;
            if (tables != null)
                table = tables[0];
            return table;
        }
        #endregion

        #region 获取住院医嘱明细表（Inpatient_DrAdvice_Detail）对应inpatient_physician_order_MDT
        public DataTable getInpatientDrAdviceDetailRecordWard(int seqid, DopServiceHelp help, string[] attr)
        {

            DateTime dt1 = DateTime.Now;
            double t1 = dt1.ToOADate();

            String expression = " <%physician_order_serial_number_seq%> > " + seqid;
            String mdtname = "inpatient_physician_order_MDT";
            String orderByAttr = "physician_order_serial_number_seq";
            Console.WriteLine(expression);
            DataTable[] tables = help.GetDataByExpression(mdtname, expression, attr, null, null, false, null, orderByAttr);

            DataTable table = null;
            if (tables != null)
                table = tables[0];
            return table;
        }
        #endregion


        #region 获取检验指标表（LIS_Indicators）对应 lab_result_MDT
        public DataTable getLISIndicatorsRecordWard(int seqid, DopServiceHelp help, string[] attr)
        {
            DateTime dt1 = DateTime.Now;
            double t1 = dt1.ToOADate();

            String expression = " <%specimen_id%> > " + seqid;
            String mdtname = "lab_result_MDT";
            String orderByAttr = "lab_report_id";

            DataTable[] tables = help.GetDataByExpression(mdtname, expression, attr, null, null, false, null, orderByAttr);

            DataTable table = null;
            if (tables != null)
                table = tables[0];
            return table;
        }
        #endregion
        //有问题主键是字符型，不能使用seq自增方法取到

        #region 获取药敏结果（LIS_Allergy_Result）对应 drug_susceptibility_test_result_MDT
        public DataTable getLISALLergyResultRecordWard(int seqid, DopServiceHelp help, string[] attr)
        {
            DateTime dt1 = DateTime.Now;
            double t1 = dt1.ToOADate();

            String expression = " <%drug_test_serial_number_seq%> > " + seqid;
            String mdtname = "drug_susceptibility_test_result_MDT";
            String orderByAttr = "drug_test_serial_number_seq";
            DataTable[] tables = help.GetDataByExpression(mdtname, expression, attr, null, null, false, null, orderByAttr);

            DataTable table = null;
            if (tables != null)
                table = tables[0];
            return table;
        }
        #endregion

        #region 获取细菌结果（LIS_Bacteria_Result）对应 bacteria_test_result_MDT
        public DataTable getLISBacteriaResultRecordWard(int seqid, DopServiceHelp help, string[] attr)
        {
            DateTime dt1 = DateTime.Now;
            double t1 = dt1.ToOADate();

            String expression = " <%bacteria_test_serial_number_seq%> > " + seqid;
            String mdtname = "bacteria_test_result_MDT";
            String orderByAttr = "bacteria_test_serial_number_seq";
            DataTable[] tables = help.GetDataByExpression(mdtname, expression, attr, null, null, false, null, orderByAttr);

            DataTable table = null;
            if (tables != null)
                table = tables[0];
            return table;
        }

        #endregion

        #region 获取住院病历手术明细表（CIS_Operation_Detail）对应 inpatient_medical_record_operation_item_MDT
        public DataTable getCISOperationDetailRecordWard(int seqid, DopServiceHelp help, string[] attr)
        {
            DateTime dt1 = DateTime.Now;
            double t1 = dt1.ToOADate();

            String expression = " <%operation_item_seq%> > " + seqid;
            String mdtname = "inpatient_medical_record_operation_item_MDT";
            String orderByAttr = "operation_item_seq";
            DataTable[] tables = help.GetDataByExpression(mdtname, expression, attr, null, null, false, null, orderByAttr);

            DataTable table = null;
            if (tables != null)
                table = tables[0];
            return table;
        }
        #endregion

        #region 获取住院病历主表（CIS_Main）对应 inpatient_medical_record_MDT
        public DataTable getCISMainRecordWard(int seqid, DopServiceHelp help, string[] attr)
        {
            DateTime dt1 = DateTime.Now;
            double t1 = dt1.ToOADate();

            String expression = " <%inpatient_id%> > " + seqid;
            String mdtname = "inpatient_medical_record_MDT";
            String orderByAttr = "inpatient_id";
            DataTable[] tables = help.GetDataByExpression(mdtname, expression, attr, null, null, false, null, orderByAttr);

            DataTable table = null;
            if (tables != null)
                table = tables[0];
            return table;
        }
        #endregion

        #region 获取住院收费结算表（Inpatient_Fee_Settle）对应inpatient_patient_settle_MDT
        public DataTable getInpatientFeeSettleRecordWard(int seqid, DopServiceHelp help, string[] attr)
        {
            DateTime dt1 = DateTime.Now;
            double t1 = dt1.ToOADate();

            String expression = " <%original_system_code%> > " + seqid;
            String mdtname = "inpatient_patient_settle_MDT";
            String orderByAttr = "original_system_code";
            DataTable[] tables = help.GetDataByExpression(mdtname, expression, attr, null, null, false, null, orderByAttr);

            DataTable table = null;
            if (tables != null)
                table = tables[0];
            return table;
        }
        #endregion

        #region 获取门诊收费结算表（Outpatient_Fee_Settle）对应Outpatient_patient_settle_MDT
        public DataTable getOutpatientFeeSettleRecordWard(int seqid, DopServiceHelp help, string[] attr)
        {
            DateTime dt1 = DateTime.Now;
            double t1 = dt1.ToOADate();

            String expression = " <%original_system_code%> > " + seqid;
            String mdtname = "Outpatient_patient_settle_MDT";
            String orderByAttr = "original_system_code";
            DataTable[] tables = help.GetDataByExpression(mdtname, expression, attr, null, null, false, null, orderByAttr);

            DataTable table = null;
            if (tables != null)
                table = tables[0];
            return table;
        }
        #endregion

        #region 获取住院收费明细表（Inpatient_Fee_Detail）对应inpatient_patient_fee_record_MDT
        public DataTable getInpatientFeeDetailRecordWard(int seqid, DopServiceHelp help, string[] attr)
        {
            DateTime dt1 = DateTime.Now;
            double t1 = dt1.ToOADate();

            String expression = " <%original_system_code%> > " + seqid;
            String mdtname = "inpatient_patient_fee_record_MDT";
            String orderByAttr = "original_system_code";
            DataTable[] tables = help.GetDataByExpression(mdtname, expression, attr, null, null, false, null, orderByAttr);

            DataTable table = null;
            if (tables != null)
                table = tables[0];
            return table;
        }
        #endregion

        #region 获取门诊收费明细表（Outpatient_Fee_Detail）对应outpatient_patient_fee_record_MDT
        public DataTable getOutpatientFeeDetailRecordWard(int seqid, DopServiceHelp help, string[] attr)
        {
            DateTime dt1 = DateTime.Now;
            double t1 = dt1.ToOADate();

            String expression = " <%settle_receipt_serial_number%> > " + seqid;
            String mdtname = "outpatient_patient_fee_record_MDT";
            String orderByAttr = "settle_receipt_serial_number";
            DataTable[] tables = help.GetDataByExpression(mdtname, expression, attr, null, null, false, null, orderByAttr);

            DataTable table = null;
            if (tables != null)
                table = tables[0];
            return table;
        }
        #endregion

        #region 获取结算费别表（Settle_Fee_Type）对应settle_fee_type_MDT
        public DataTable getSettleFeeTypeRecordWard(int seqid, DopServiceHelp help, string[] attr)
        {
            DateTime dt1 = DateTime.Now;
            double t1 = dt1.ToOADate();

            String expression = " <%settle_receipt_serial_number%> > " + seqid;
            String mdtname = "settle_fee_type_MDT";
            String orderByAttr = "settle_receipt_serial_number";
            DataTable[] tables = help.GetDataByExpression(mdtname, expression, attr, null, null, false, null, orderByAttr);

            DataTable table = null;
            if (tables != null)
                table = tables[0];
            return table;
        }
        #endregion

        #region 门诊记录表（Outpatient_Record）对应outpatient_registration_MDT
        public DataTable getOutpatientRecordRecordWard(int seqid, DopServiceHelp help, string[] attr)
        {
            DateTime dt1 = DateTime.Now;
            double t1 = dt1.ToOADate();

            String expression = " <%encounter_serial_number_seq%> > " + seqid;
            String mdtname = "outpatient_registration_MDT";
            String orderByAttr = "encounter_serial_number_seq";
            DataTable[] tables = help.GetDataByExpression(mdtname, expression, attr, null, null, false, null, orderByAttr);

            DataTable table = null;
            if (tables != null)
                table = tables[0];
            return table;
        }
        #endregion

        #region 住院记录表（Inpatient_Record）对应inpatient_record_MDT
        public DataTable getInpatientRecordRecordWard(int seqid, DopServiceHelp help, string[] attr)
        {
            DateTime dt1 = DateTime.Now;
            double t1 = dt1.ToOADate();

            String expression = " <%encounter_serial_number_seq%> > " + seqid;
            String mdtname = "inpatient_record_MDT";
            String orderByAttr = "encounter_serial_number_seq";
            DataTable[] tables = help.GetDataByExpression(mdtname, expression, attr, null, null, false, null, orderByAttr);

            DataTable table = null;
            if (tables != null)
                table = tables[0];
            return table;
        }
        #endregion

        #region 获取收费记录表（Fee_Record）对应inpatient_patient_settle_MDT
        public DataTable getFeeRecordRecordWard(String ward_name, DopServiceHelp help)
        {
            int seqid = 0;

            DateTime dt1 = DateTime.Now;
            double t1 = dt1.ToOADate();

            String expression = " <%encounter_serial_number%> > " + seqid;

            if (ward_name != null && !ward_name.Equals(""))
            {
                expression = " and <%ward_name%> = '" + ward_name + "'";
            }


            String mdtname = "inpatient_patient_settle_MDT";

            Console.WriteLine(expression);

            String[] attr = { "original_system_code", "encounter_serial_number", "card_number", "card_type", "medical_institution_code", "total_money_amount", "public_insurance_eligible_total", "public_insurance_pay_total", "insurance_self_pay_amount", "public_insurance_copay_item", "public_insurance_not_covered", "settle_time", "settle_receipt_serial_number" };
            //病人标识号还不确定
            //String[] attr = { "original_system_code" };
            String orderByAttr = "encounter_serial_number";
            Console.WriteLine(expression);
            DataTable[] tables = help.GetDataByExpression(mdtname, expression, attr, null, null, false, null, orderByAttr);

            DataTable table = null;
            if (tables != null)
                table = tables[0];
            return table;
        }
        #endregion

        #region 获取收费明细表（Fee_Detail）对应patient_fee_record_MDT
        public DataTable getFeeDetailRecordWard(String ward_name, DopServiceHelp help)
        {
            int seqid = 0;

            DateTime dt1 = DateTime.Now;
            double t1 = dt1.ToOADate();

            String expression = " <%settle_receipt_serial_number%> > " + seqid;

            if (ward_name != null && !ward_name.Equals(""))
            {
                expression = " and <%ward_name%> = '" + ward_name + "'";
            }


            String mdtname = "patient_fee_record_MDT";

            Console.WriteLine(expression);

            //String[] attr = { "settle_receipt_serial_number", "is_charge_or_refund", "card_type", "card_number", "medical_institution_code", "fee_type_code", "item_code", "item_name", "item_unit", "retail_price", "amount", "total_money_amount", "public_insurance_not_covered_item","public_insurance_copay_detail_item" };
            //病人标识号还不确定
            String[] attr = { "settle_receipt_serial_number" };
            String orderByAttr = "settle_receipt_serial_number";
            Console.WriteLine(expression);
            DataTable[] tables = help.GetDataByExpression(mdtname, expression, attr, null, null, false, null, orderByAttr);

            DataTable table = null;
            if (tables != null)
                table = tables[0];
            return table;
        }
        #endregion

   

      

   

    }
}
